package com.itcast.contraller;

import com.itcast.pojo.Clazz;
import com.itcast.pojo.ClazzQueryParam;
import com.itcast.pojo.PageResult;
import com.itcast.pojo.Result;
import com.itcast.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    /*
    * 分页查询班级信息
    * */
    @GetMapping("/clazzs")
    public Result getClazzByPage(ClazzQueryParam clazzQueryParam){
        log.info("分页查询班级信息{}",clazzQueryParam);
        PageResult<Clazz> pageResult= clazzService.getClazzByPage(clazzQueryParam);
        return Result.success(pageResult);
    }
    /*
    * 根据id删除班级信息
    * */
    @DeleteMapping("/clazzs/{id}")
    public Result deleteClazzById(@PathVariable Integer id){
        log.info("删除班级信息{}",id);
        clazzService.deleteClazzById(id);
        return Result.success();
    }
    /*
    * 添加班级信息
    * */
    @PostMapping("/clazzs")
    public  Result addClazz(@RequestBody Clazz clazz){
        log.info("添加班级信息{}",clazz);
        clazzService.addClazz(clazz);
        return Result.success();
    }
    /*
    * 根据id查询班级信息
    * */
    @GetMapping("/clazzs/{id}")
    public Result findClazzById(@PathVariable Integer id){
        log.info("查询班级信息{}",id);
       Clazz clazz=clazzService.findClazzById(id);
        return Result.success(clazz);
    }
    /*
    * 根据id修改班级信息
    * */
    @PutMapping("/clazzs")
    public Result updateClazzById(@RequestBody Clazz clazz){
        log.info("修改班级信息{}",clazz);
        clazzService.updateClazzById(clazz);
        return Result.success();
    }
    /*
     *
     * 查询所有班级
     */

    @GetMapping("/clazzs/list")
    public Result findAllClazz(){
        log.info("查询所有班级");
        List<Clazz> clazzList = clazzService.findAllClazz();
        return Result.success(clazzList);
    }
}
